package com.come4loves.game.module.skill.skillcardimpl;

import org.springframework.stereotype.Component;

import com.come4loves.core.utils.Splitable;
import com.come4loves.game.dataconfig.model.BuffEffectConfig;
import com.come4loves.game.dataconfig.service.BuffEffectService;
import com.come4loves.game.module.fight.action.BatchAction;
import com.come4loves.game.module.fight.model.FightCard;
import com.come4loves.game.module.fight.model.FightContext;
import com.come4loves.game.module.skill.AbstractBuffParser;
import com.come4loves.game.module.skill.AbstractSkillCardParser;
import com.come4loves.game.module.skill.model.SkillModel;
@Component
public class BuffHandler extends AbstractSkillCardParser {
	
	@Override
	public String skillId() {
		return "buff";
	}

	@Override
	public void handerSkill(FightCard attackerCard, FightCard targetCard, SkillModel skillModel, BatchAction batchAction, FightContext fightContext) {
		if (targetCard.isDead()) {
			return;
		}
		String[] temp = skillModel.getEffect().get(skillId()).split(Splitable.BETWEEN_DOT);
		for (String bid : temp) {
			int effectValue = Integer.valueOf(bid);
			if (effectValue > 0){
				BuffEffectConfig cfg = BuffEffectService.get(effectValue);
				if (cfg == null) {
					LOGGER.error("buff config not exsit, id:{}",effectValue);
					continue;
				}
				String buffType = cfg.getBuffactor();
				AbstractBuffParser buffParser = AbstractBuffParser.get(buffType);
				if (buffParser == null) {
					LOGGER.error("buff not handle,type:{},cardid:{},cardtype:",buffType,targetCard.getCfgId(),targetCard.getCardType());
				} else {
					buffParser.parse(attackerCard, targetCard, cfg, batchAction);
				}
				
			}
		}
	}

}
